package com.gdut.laiagent.demo.invoke;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * SpringAI调用阿里云灵积大模型
 * 只要springboot启动就会自动执行一次，因为CommandLineRunner
 */
//@Component
public class SpringAIAIInvoke implements CommandLineRunner {

    // spring能根据名称自动找到对应的大模型，然后注入，后续直接调用
    @Resource
    private ChatModel dashscopeChatModel;

    @Override
    public void run(String... args) throws Exception {
        AssistantMessage assistantMessage = dashscopeChatModel.call(new Prompt("你好，我是刘光辉"))
                .getResult()
                .getOutput();
        System.out.println(assistantMessage);
    }
}
